<!DOCTYPE html>
<html lang="zh">
    <head>
    <!--
        © Material Theme
        https://github.com/viosey/hexo-theme-material
        Version: 1.3.4 -->

    <!-- Title -->
    
    <title>
        
            MySQL---子查询、表的连接 | 
        
        Twilight&#39;s Blog
    </title>

    <!-- Meta & Info -->
    <meta charset="utf-8">

    <!-- dns prefetch -->
    <meta http-equiv="x-dns-prefetch-control" content="on">
    
    
        <link rel="dns-prefetch" href="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"/>
    
    
        <link rel="dns-prefetch" href="https://changyan.sohu.com"/>
    
    
    
    

    <meta http-equiv="X-UA-Compatible">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="theme-color" content="#0097A7">
    <meta name="author" content="wangchao">
    <meta name="description" content="null">
    <meta name="keywords" content="null,MySQL">

    <!-- Favicons -->
    <link rel="icon shortcut" type="image/ico" href="/img/favicon.png">
    <link rel="icon" sizes="192x192" href="/img/favicon.png">
    <link rel="apple-touch-icon" href="/img/favicon.png">

    <!--iOS -->
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-title" content="Title">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="HandheldFriendly" content="True">
    <meta name="MobileOptimized" content="480">

    <!-- Add to homescreen for Chrome on Android -->
    <meta name="mobile-web-app-capable" content="yes">

    <!-- Add to homescreen for Safari on iOS -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-title" content="Twilight&#39;s Blog">

    <!-- The Open Graph protocol -->
    <meta property="og:url" content="http://yoursite.com">
    <meta property="og:type" content="blog">
    <meta property="og:title" content="MySQL---子查询、表的连接 | Twilight&#39;s Blog">
    <meta property="og:description" content="null">
    <meta property="og:article:tag" content="MySQL"> 

    <!--[if lte IE 9]>
        <link rel="stylesheet" href="/css/ie-blocker.css">

        
            <script src="/js/ie-blocker.zhCN.js"></script>
        
    <![endif]-->

    <!-- Import CSS & jQuery -->
    
        <link rel="stylesheet" href="/css/material.min.css">
        <link rel="stylesheet" href="/css/style.min.css">
        <!-- Config CSS -->


<!-- Other Styles -->
<style>
  body, html {
    font-family: Roboto, "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
  }

  a {
    color: #00838F;
  }

  .mdl-card__media,
  #search-label,
  #search-form-label:after,
  #scheme-Paradox .hot_tags-count,
  #scheme-Paradox .sidebar_archives-count,
  #scheme-Paradox .sidebar-colored .sidebar-header,
  #scheme-Paradox .sidebar-colored .sidebar-badge{
    background-color: #0097A7 !important;
  }

  /* Sidebar User Drop Down Menu Text Color */
  #scheme-Paradox .sidebar-colored .sidebar-nav>.dropdown>.dropdown-menu>li>a:hover,
  #scheme-Paradox .sidebar-colored .sidebar-nav>.dropdown>.dropdown-menu>li>a:focus {
    color: #0097A7 !important;
  }

  #post_entry-right-info,
  .sidebar-colored .sidebar-nav li:hover > a,
  .sidebar-colored .sidebar-nav li:hover > a i,
  .sidebar-colored .sidebar-nav li > a:hover,
  .sidebar-colored .sidebar-nav li > a:hover i,
  .sidebar-colored .sidebar-nav li > a:focus i,
  .sidebar-colored .sidebar-nav > .open > a,
  .sidebar-colored .sidebar-nav > .open > a:hover,
  .sidebar-colored .sidebar-nav > .open > a:focus,
  #ds-reset #ds-ctx .ds-ctx-entry .ds-ctx-head a {
    color: #0097A7 !important;
  }

  .toTop {
    background: #757575 !important;
  }

  .material-layout .material-post>.material-nav,
  .material-layout .material-index>.material-nav,
  .material-nav a {
    color: #757575;
  }

  #scheme-Paradox .MD-burger-layer {
    background-color: #757575;
  }

  #scheme-Paradox #post-toc-trigger-btn {
    color: #757575;
  }

  .post-toc a:hover {
    color: #00838F;
    text-decoration: underline;
  }

</style>


<!-- Theme Background Related-->

    <style>
      body{
        background-image: url(/img/bg.jpg);
      }
    </style>




<!-- Fade Effect -->

    <style>
      .fade {
        transition: all 800ms linear;
        -webkit-transform: translate3d(0,0,0);
        -moz-transform: translate3d(0,0,0);
        -ms-transform: translate3d(0,0,0);
        -o-transform: translate3d(0,0,0);
        transform: translate3d(0,0,0);
        opacity: 1;
      }

      .fade.out{
        opacity: 0;
      }
    </style>


        <script src="/js/jquery.min.js"></script>
        <script src="/js/queue.js"></script>
    

    <!-- UC Browser Compatible -->
    <script>
        var agent = navigator.userAgent.toLowerCase();
        if(agent.indexOf('ucbrowser')>0) {
            document.write("<link rel=\"stylesheet\" href=\"/css/uc.css\">");
            alert('由于 UC 浏览器使用极旧的内核，而本网站使用了一些新的特性。\n为了您能更好的浏览，推荐使用 Chrome 或 Firefox 浏览器。');
        }
    </script>

    

    


    <!-- Bing Background -->
    

    <!-- Custom Head -->
    
</head>


    
        <body id="scheme-Paradox" class="lazy">
            <div class="material-layout  mdl-js-layout has-drawer is-upgraded">
                

                <!-- Main Container -->
                <main class="material-layout__content" id="main">

                    <!-- Top Anchor -->
                    <div id="top"></div>

                    
                        <!-- Hamburger Button -->
                        <button class="MD-burger-icon sidebar-toggle">
                            <span class="MD-burger-layer"></span>
                        </button>
                    

                    <!-- Post TOC -->

    
    <!-- Back Button -->
    <!--
    <div class="material-back" id="backhome-div" tabindex="0">
        <a class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon"
           href="#" onclick="window.history.back();return false;"
           target="_self"
           role="button"
           data-upgraded=",MaterialButton,MaterialRipple">
            <i class="material-icons" role="presentation">arrow_back</i>
            <span class="mdl-button__ripple-container">
                <span class="mdl-ripple"></span>
            </span>
        </a>
    </div>
    -->

    <!-- Left aligned menu below button -->
    <button id="post-toc-trigger-btn"
        class="mdl-button mdl-js-button mdl-button--icon">
        <i class="material-icons">format_list_numbered</i>
    </button>

    <ul class="post-toc-wrap mdl-menu mdl-menu--bottom-left mdl-js-menu mdl-js-ripple-effect" for="post-toc-trigger-btn" style="max-height:80vh; overflow-y:scroll;">
        <ol class="post-toc"><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#子查询"><span class="post-toc-number">1.</span> <span class="post-toc-text">子查询</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#IN-和NOT-IN"><span class="post-toc-number">1.1.</span> <span class="post-toc-text">IN 和NOT IN</span></a></li></ol></li><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#EXISTS"><span class="post-toc-number">2.</span> <span class="post-toc-text">EXISTS</span></a></li><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#INSERT-INTO-tbl-name-col-name-…-SELECT-…"><span class="post-toc-number">3.</span> <span class="post-toc-text">INSERT INTO tbl_name [(col_name,…)] SELECT …</span></a></li><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#多表更新"><span class="post-toc-number">4.</span> <span class="post-toc-text">多表更新</span></a></li><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#创建表的同时插入数据"><span class="post-toc-number">5.</span> <span class="post-toc-text">创建表的同时插入数据</span></a></li><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#连接类型"><span class="post-toc-number">6.</span> <span class="post-toc-text">连接类型</span></a></li><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#多表连接"><span class="post-toc-number">7.</span> <span class="post-toc-text">多表连接</span></a></li><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#多表删除"><span class="post-toc-number">8.</span> <span class="post-toc-text">多表删除</span></a></li></ol>

        <!--
        <li class="mdl-menu__item">
            Some Action
        </li>
        -->
    </ul>




<!-- Layouts -->

    <!-- Post Module -->
    <div class="material-post_container">

        <div class="material-post mdl-grid">
            <div class="mdl-card mdl-shadow--4dp mdl-cell mdl-cell--12-col">

                <!-- Post Header(Thumbnail & Title) -->
                
    <!-- Paradox Post Header -->
    
        <!-- Custom Thumbnail -->
        <div class="post_thumbnail-custom mdl-card__media mdl-color-text--grey-50" style="background-image:url(http://otbrtx8bw.bkt.clouddn.com/hexo_title_mysql-%E5%AD%90%E6%9F%A5%E8%AF%A2%EF%BC%8C%E8%A1%A8%E7%9A%84%E9%93%BE%E6%8E%A5.jpg)">
    
            <p class="article-headline-p">
                MySQL---子查询、表的连接
            </p>
        </div>





                
                    <!-- Paradox Post Info -->
                    <div class="mdl-color-text--grey-700 mdl-card__supporting-text meta">

    <!-- Author Avatar -->
    <div id="author-avatar">
        <img src="/img/avatar.png" width="44px" height="44px" alt="Author Avatar"/>
    </div>
    <!-- Author Name & Date -->
    <div>
        <strong>wangchao</strong>
        <span>7月 08, 2017</span>
    </div>

    <div class="section-spacer"></div>

    <!-- Favorite -->
    <!--
        <button id="article-functions-like-button" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon btn-like">
            <i class="material-icons" role="presentation">favorite</i>
            <span class="visuallyhidden">favorites</span>
        </button>
    -->

    <!-- Qrcode -->
    

    <!-- Tags (bookmark) -->
    
    <button id="article-functions-viewtags-button" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon">
        <i class="material-icons" role="presentation">bookmark</i>
        <span class="visuallyhidden">bookmark</span>
    </button>
    <ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu mdl-js-ripple-effect" for="article-functions-viewtags-button">
        <li class="mdl-menu__item">
        <a class="post_tag-link" href="/tags/MySQL/">MySQL</a>
    </ul>
    

    <!-- Share -->
    <button id="article-fuctions-share-button" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon">
    <i class="material-icons" role="presentation">share</i>
    <span class="visuallyhidden">share</span>
</button>
<ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu mdl-js-ripple-effect" for="article-fuctions-share-button">
    
    <!-- Leancloud Views -->
        <a class="post_share-link" href="#">
            <li class="mdl-menu__item">
                <span id="/2017/07/08/MySQL-子查询、表的连接/" class="leancloud-views_num" data-flag-title="MySQL---子查询、表的连接">
     &nbsp;浏览量
</span>

            </li>
        </a>
    

    

    <!-- Share Weibo -->
    
        <a class="post_share-link" href="http://service.weibo.com/share/share.php?appkey=&title=MySQL---子查询、表的连接&url=http://yoursite.com//2017/07/08/MySQL-子查询、表的连接/index.html&pic=&searchPic=false&style=simple" target="_blank">
            <li class="mdl-menu__item">
                分享到微博
            </li>
        </a>
    

    <!-- Share Twitter -->
    
        <a class="post_share-link" href="https://twitter.com/intent/tweet?text=MySQL---子查询、表的连接&url=http://yoursite.com//2017/07/08/MySQL-子查询、表的连接/index.html&via=wangchao" target="_blank">
            <li class="mdl-menu__item">
                分享到 Twitter
            </li>
        </a>
    

    <!-- Share Facebook -->
    
        <a class="post_share-link" href="https://www.facebook.com/sharer/sharer.php?u=http://yoursite.com//2017/07/08/MySQL-子查询、表的连接/index.html" target="_blank">
            <li class="mdl-menu__item">
                分享到 Facebook
            </li>
        </a>
    

    <!-- Share Google+ -->
    
        <a class="post_share-link" href="https://plus.google.com/share?url=http://yoursite.com//2017/07/08/MySQL-子查询、表的连接/index.html" target="_blank">
            <li class="mdl-menu__item">
                分享到 Google+
            </li>
        </a>
    

    <!-- Share LinkedIn -->
    

    <!-- Share QQ -->
    
        <a class="post_share-link" href="http://connect.qq.com/widget/shareqq/index.html?site=Twilight&#39;s Blog&title=MySQL---子查询、表的连接&summary=null&pics=http://yoursite.com/img/favicon.png&url=http://yoursite.com/2017/07/08/MySQL-子查询、表的连接/index.html" target="_blank">
            <li class="mdl-menu__item">
                分享到 QQ
            </li>
        </a>
    

    <!-- Share Telegram -->
    
</ul>

</div>

                

                <!-- Post Content -->
                <div id="post-content" class="mdl-color-text--grey-700 mdl-card__supporting-text fade out">
    
        <h1 id="子查询"><a href="#子查询" class="headerlink" title="子查询"></a>子查询</h1><p>常用的比较运算符： =、&gt;、&lt;、&gt;=、&lt;=、&lt;&gt;、!=、&lt;=&gt;</p>
<p>修饰运算符<br><a id="more"></a></p>
<table>
<thead>
<tr>
<th style="text-align:center">运算符</th>
<th style="text-align:center">关键字</th>
<th style="text-align:center">关键字</th>
<th style="text-align:center">关键字</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">&nbsp;</td>
<td style="text-align:center">ANY</td>
<td style="text-align:center">SOME</td>
<td style="text-align:center">ALL</td>
</tr>
<tr>
<td style="text-align:center">&gt;、&gt;=</td>
<td style="text-align:center">最小值</td>
<td style="text-align:center">最小值</td>
<td style="text-align:center">最大值</td>
</tr>
<tr>
<td style="text-align:center">&lt;、&lt;=</td>
<td style="text-align:center">最大值</td>
<td style="text-align:center">最大值</td>
<td style="text-align:center">最小值</td>
</tr>
<tr>
<td style="text-align:center">=</td>
<td style="text-align:center">任意值</td>
<td style="text-align:center">任意值</td>
<td style="text-align:center">&nbsp;</td>
</tr>
<tr>
<td style="text-align:center">&lt;&gt;、!=</td>
<td style="text-align:center">&nbsp;</td>
<td style="text-align:center">&nbsp;</td>
<td style="text-align:center">任意值</td>
</tr>
</tbody>
</table>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">// 查找所有价格大于平均值的行</div><div class="line">mysql&gt; SELECT goods_id,goods_name,goods_price FROM tdb_goods</div><div class="line">    -&gt; WHERE goods_price &gt; (SELECT ROUND(AVG(goods_price)) FROM tdb_goods)</div><div class="line">    -&gt; ORDER BY goods_price;</div></pre></td></tr></table></figure>
<p>运算符=ANY 和 =SOME 相当于 IN<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">=ANY =SOME --IN</div><div class="line">mysql&gt; SELECT goods_id,goods_name,goods_price FROM tdb_goods WHERE goods_price = ANY (SELECT goods_price FROM tdb_goods WHERE goods_cate=&apos;超级本&apos;);</div><div class="line">+----------+---------------------------------+-------------+</div><div class="line">| goods_id | goods_name                      | goods_price |</div><div class="line">+----------+---------------------------------+-------------+</div><div class="line">|        5 | X240(20ALA0EYCD) 12.5英寸超极本 |    4999.000 |</div><div class="line">|        6 | U330P 13.3英寸超极本            |    4299.000 |</div><div class="line">|        7 | SVP13226SCB 13.3英寸触控超极本  |    7999.000 |</div><div class="line">+----------+---------------------------------+-------------+</div></pre></td></tr></table></figure></p>
<p>&gt; ANY  表示大于最小值<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line">// &gt; ANY </div><div class="line">mysql&gt; SELECT goods_id,goods_name,goods_price FROM tdb_goods WHERE goods_price &gt; ANY (SELECT goods_price FROM tdb_goods WHERE goods_cate=&apos;超级本&apos;);</div><div class="line">+----------+----------------------------------+-------------+</div><div class="line">| goods_id | goods_name                       | goods_price |</div><div class="line">+----------+----------------------------------+-------------+</div><div class="line">|        2 | Y400N 14.0英寸笔记本电脑         |    4899.000 |</div><div class="line">|        3 | G150TH 15.6英寸游戏本            |    8499.000 |</div><div class="line">|        5 | X240(20ALA0EYCD) 12.5英寸超极本  |    4999.000 |</div><div class="line">|        7 | SVP13226SCB 13.3英寸触控超极本   |    7999.000 |</div><div class="line">|       13 | iMac ME086CH/A 21.5英寸一体电脑  |    9188.000 |</div><div class="line">|       16 | PowerEdge T110 II服务器          |    5388.000 |</div><div class="line">|       17 | Mac Pro MD878CH/A 专业级台式电脑 |   28888.000 |</div><div class="line">|       18 |  HMZ-T3W 头戴显示设备            |    6999.000 |</div><div class="line">|       20 | X3250 M4机架式服务器 2583i14     |    6888.000 |</div><div class="line">|       21 |  HMZ-T3W 头戴显示设备            |    6999.000 |</div><div class="line">+----------+----------------------------------+-------------+</div></pre></td></tr></table></figure></p>
<p>&gt; ALL表示大于最大值<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">// &gt; ALL </div><div class="line">mysql&gt; SELECT goods_id,goods_name,goods_price FROM tdb_goods WHERE goods_price &gt; ALL (SELECT goods_price FROM tdb_goods WHERE goods_cate=&apos;超级本&apos;);</div><div class="line">+----------+----------------------------------+-------------+</div><div class="line">| goods_id | goods_name                       | goods_price |</div><div class="line">+----------+----------------------------------+-------------+</div><div class="line">|        3 | G150TH 15.6英寸游戏本            |    8499.000 |</div><div class="line">|       13 | iMac ME086CH/A 21.5英寸一体电脑  |    9188.000 |</div><div class="line">|       17 | Mac Pro MD878CH/A 专业级台式电脑 |   28888.000 |</div><div class="line">+----------+----------------------------------+-------------+</div></pre></td></tr></table></figure></p>
<h2 id="IN-和NOT-IN"><a href="#IN-和NOT-IN" class="headerlink" title="IN 和NOT IN"></a>IN 和NOT IN</h2><p><strong>NOT IN等效于！=ALL 或 &lt;&gt;ALL</strong><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div></pre></td><td class="code"><pre><div class="line">// NOT IN 与 ！= ALL等效 ，以下查询不是超极本的电脑，两次查询的结果相同</div><div class="line">mysql&gt; SELECT goods_id,goods_name,goods_price FROM tdb_goods WHERE goods_price NOT IN  (SELECT goods_price FROM tdb_goods WHERE goods_cate=&apos;超级本&apos;);</div><div class="line">mysql&gt; SELECT goods_id,goods_name,goods_price FROM tdb_goods WHERE goods_price != ALL  (SELECT goods_price FROM tdb_goods WHERE goods_cate=&apos;超级本&apos;);</div><div class="line">+----------+------------------------------------------------------------------------+-------------+</div><div class="line">| goods_id | goods_name                                                             | goods_price |</div><div class="line">+----------+------------------------------------------------------------------------+-------------+</div><div class="line">|        1 | R510VC 15.6英寸笔记本                                                  |    3399.000 |</div><div class="line">|        2 | Y400N 14.0英寸笔记本电脑                                               |    4899.000 |</div><div class="line">|        3 | G150TH 15.6英寸游戏本                                                  |    8499.000 |</div><div class="line">|        4 | X550CC 15.6英寸笔记本                                                  |    2799.000 |</div><div class="line">|        8 | iPad mini MD531CH/A 7.9英寸平板电脑                                    |    1998.000 |</div><div class="line">|        9 | iPad Air MD788CH/A 9.7英寸平板电脑 （16G WiFi版）                      |    3388.000 |</div><div class="line">|       10 |  iPad mini ME279CH/A 配备 Retina 显示屏 7.9英寸平板电脑 （16G WiFi版） |    2788.000 |</div><div class="line">|       11 | IdeaCentre C340 20英寸一体电脑                                         |    3499.000 |</div><div class="line">|       12 | Vostro 3800-R1206 台式电脑                                             |    2899.000 |</div><div class="line">|       13 | iMac ME086CH/A 21.5英寸一体电脑                                        |    9188.000 |</div><div class="line">|       14 | AT7-7414LP 台式电脑 （i5-3450四核 4G 500G 2G独显 DVD 键鼠 Linux ）     |    3699.000 |</div><div class="line">|       15 | Z220SFF F4F06PA工作站                                                  |    4288.000 |</div><div class="line">|       16 | PowerEdge T110 II服务器                                                |    5388.000 |</div><div class="line">|       17 | Mac Pro MD878CH/A 专业级台式电脑                                       |   28888.000 |</div><div class="line">|       18 |  HMZ-T3W 头戴显示设备                                                  |    6999.000 |</div><div class="line">|       19 | 商务双肩背包                                                           |      99.000 |</div><div class="line">|       20 | X3250 M4机架式服务器 2583i14                                           |    6888.000 |</div><div class="line">|       21 |  HMZ-T3W 头戴显示设备                                                  |    6999.000 |</div><div class="line">|       22 | 商务双肩背包                                                           |      99.000 |</div><div class="line">+----------+------------------------------------------------------------------------+-------------+</div></pre></td></tr></table></figure></p>
<h1 id="EXISTS"><a href="#EXISTS" class="headerlink" title="EXISTS"></a>EXISTS</h1><p>如果子查询返回任何行，EXISTS将返回TRUE ，否则返回FALSE<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">select * from t1 where exists (select * from t1 where id = 2);</div></pre></td></tr></table></figure></p>
<h1 id="INSERT-INTO-tbl-name-col-name-…-SELECT-…"><a href="#INSERT-INTO-tbl-name-col-name-…-SELECT-…" class="headerlink" title="INSERT INTO tbl_name [(col_name,…)] SELECT …"></a>INSERT INTO tbl_name [(col_name,…)] SELECT …</h1><p>使用查询插入数据表</p>
<p>创建分类表，用以上语句更新分类表<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; INSERT INTO tdb_goods_cate (cate_name) SELECT goods_cate FROM tdb_goods GROUP BY goods_cate;</div></pre></td></tr></table></figure></p>
<h1 id="多表更新"><a href="#多表更新" class="headerlink" title="多表更新"></a>多表更新</h1><p>UPDATE tbl_name1 [LEFT|RIGHT]JOIN tbl_name2 ON condition SET name=value… WHERE condition..</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">// 按照分类表，将商品表中的数据更新</div><div class="line">mysql&gt; UPDATE tdb_goods INNER JOIN tdb_goods_cate </div><div class="line">ON tdb_goods.goods_cate=tdb_goods_cate.cate_name </div><div class="line">SET tdb_goods.goods_cate = tdb_goods_cate.id;</div></pre></td></tr></table></figure>
<h1 id="创建表的同时插入数据"><a href="#创建表的同时插入数据" class="headerlink" title="创建表的同时插入数据"></a>创建表的同时插入数据</h1><p>CREATE TABLE [IF NOT EXISTS] tbl_name [(create_defition,…)] select_statement…</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">// 创建表的同时插入表信息</div><div class="line">mysql&gt; CREATE TABLE tdb_goods_brand(</div><div class="line">    -&gt; id INT(5) UNSIGNED PRIMARY KEY AUTO_INCREMENT,</div><div class="line">    -&gt; brand_name VARCHAR(40)</div><div class="line">    -&gt; )</div><div class="line">    -&gt; SELECT brand_name FROM tdb_goods GROUP BY brand_name;</div></pre></td></tr></table></figure>
<h1 id="连接类型"><a href="#连接类型" class="headerlink" title="连接类型"></a>连接类型</h1><ul>
<li><strong>INNER JOIN ： 内链接。 显示左表和右表都存在的记录（显示交集）</strong></li>
<li><strong>LEFT [OUTER] JOIN ： 左外连接 ，显示左表的所有记录和右表中满足条件的记录</strong></li>
<li><p><strong>RIGHT [OUUTER] JOIN ： 右外连接，显示右表的所有记录和左表中满足条件的记录</strong></p>
</li>
<li><p>在MySQL中，JOIN,CROSS JOIN 和INNER JOIN 是等价的 </p>
</li>
<li>用ON 关键字类设定连接条件，也可以使用WHERE来代替。通常使用ON关键字类设定连接条件。使用WHERE关键字今昔你个结果集记录的过滤</li>
</ul>
<h1 id="多表连接"><a href="#多表连接" class="headerlink" title="多表连接"></a>多表连接</h1><p>mysql&gt; SELECT goods_id,goods_name,cate_name,brand_name,goods_price,is_show ,is_saleoff<br>    -&gt; FROM tdb_goods g<br>    -&gt; JOIN tdb_goods_cate c on c.id = g.goods_cate_id<br>    -&gt; JOIN tdb_goods_brand b on b.id = g.brand_id;<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div></pre></td><td class="code"><pre><div class="line">// 多表查询</div><div class="line">mysql&gt; SELECT goods_id,goods_name,cate_name,brand_name,goods_price,is_show ,is_saleoff </div><div class="line">FROM tdb_goods </div><div class="line">INNER JOIN tdb_goods_cate ON tdb_goods.goods_cate_id = tdb_goods_cate.id </div><div class="line">INNER JOIN  tdb_goods_brand ON tdb_goods.brand_id = tdb_goods_brand.id;</div><div class="line"></div><div class="line">// 使用AS未每个表重命名</div><div class="line">mysql&gt; SELECT goods_id,goods_name,cate_name,brand_name,goods_price,is_show ,is_saleoff</div><div class="line">    -&gt; FROM tdb_goods g</div><div class="line">    -&gt; JOIN tdb_goods_cate c on c.id = g.goods_cate_id</div><div class="line">    -&gt; JOIN tdb_goods_brand b on b.id = g.brand_id;</div><div class="line"></div><div class="line">// 结果相同</div><div class="line">+----------+------------------------------------------------------------------------+---------------+------------+-------------+---------+------------+</div><div class="line">| goods_id | goods_name                                                             | cate_name     | brand_name | goods_price | is_show | is_saleoff |</div><div class="line">+----------+------------------------------------------------------------------------+---------------+------------+-------------+---------+------------+</div><div class="line">|        1 | R510VC 15.6英寸笔记本                                                  | 笔记本        | 华硕       |    3399.000 |       1 |          0 |</div><div class="line">|        2 | Y400N 14.0英寸笔记本电脑                                               | 笔记本        | 联想       |    4899.000 |       1 |          0 |</div><div class="line">|        3 | G150TH 15.6英寸游戏本                                                  | 游戏本        | 雷神       |    8499.000 |       1 |          0 |</div><div class="line">|        4 | X550CC 15.6英寸笔记本                                                  | 笔记本        | 华硕       |    2799.000 |       1 |          0 |</div><div class="line">|        5 | X240(20ALA0EYCD) 12.5英寸超极本                                        | 超级本        | 联想       |    4999.000 |       1 |          0 |</div><div class="line">|        6 | U330P 13.3英寸超极本                                                   | 超级本        | 联想       |    4299.000 |       1 |          0 |</div><div class="line">|        7 | SVP13226SCB 13.3英寸触控超极本                                         | 超级本        | 索尼       |    7999.000 |       1 |          0 |</div><div class="line">|        8 | iPad mini MD531CH/A 7.9英寸平板电脑                                    | 平板电脑      | 苹果       |    1998.000 |       1 |          0 |</div><div class="line">|        9 | iPad Air MD788CH/A 9.7英寸平板电脑 （16G WiFi版）                      | 平板电脑      | 苹果       |    3388.000 |       1 |          0 |</div><div class="line">|       10 |  iPad mini ME279CH/A 配备 Retina 显示屏 7.9英寸平板电脑 （16G WiFi版） | 平板电脑      | 苹果       |    2788.000 |       1 |          0 |</div><div class="line">|       11 | IdeaCentre C340 20英寸一体电脑                                         | 台式机        | 联想       |    3499.000 |       1 |          0 |</div><div class="line">|       12 | Vostro 3800-R1206 台式电脑                                             | 台式机        | 戴尔       |    2899.000 |       1 |          0 |</div><div class="line">|       13 | iMac ME086CH/A 21.5英寸一体电脑                                        | 台式机        | 苹果       |    9188.000 |       1 |          0 |</div><div class="line">|       14 | AT7-7414LP 台式电脑 （i5-3450四核 4G 500G 2G独显 DVD 键鼠 Linux ）     | 台式机        | 宏碁       |    3699.000 |       1 |          0 |</div><div class="line">|       15 | Z220SFF F4F06PA工作站                                                  | 服务器/工作站 | 惠普       |    4288.000 |       1 |          0 |</div><div class="line">|       16 | PowerEdge T110 II服务器                                                | 服务器/工作站 | 戴尔       |    5388.000 |       1 |          0 |</div><div class="line">|       17 | Mac Pro MD878CH/A 专业级台式电脑                                       | 服务器/工作站 | 苹果       |   28888.000 |       1 |          0 |</div><div class="line">|       18 |  HMZ-T3W 头戴显示设备                                                  | 笔记本配件    | 索尼       |    6999.000 |       1 |          0 |</div><div class="line">|       19 | 商务双肩背包                                                           | 笔记本配件    | 索尼       |      99.000 |       1 |          0 |</div><div class="line">|       20 | X3250 M4机架式服务器 2583i14                                           | 服务器/工作站 | IBM        |    6888.000 |       1 |          0 |</div><div class="line">|       21 |  HMZ-T3W 头戴显示设备                                                  | 笔记本配件    | 索尼       |    6999.000 |       1 |          0 |</div><div class="line">|       22 | 商务双肩背包                                                           | 笔记本配件    | 索尼       |      99.000 |       1 |          0 |</div><div class="line">+----------+------------------------------------------------------------------------+---------------+------------+-------------+---------+------------+</div></pre></td></tr></table></figure></p>
<p>无限分组：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div></pre></td><td class="code"><pre><div class="line">// 使用左连接查询每个子类的父类</div><div class="line">mysql&gt;  SELECT s.type_id AS son_id, s.type_name AS son_name,p.type_name AS parent_name</div><div class="line">    -&gt; FROM tdb_goods_types AS s LEFT JOIN tdb_goods_types AS p</div><div class="line">    -&gt; ON s.parent_id = p.type_id;</div><div class="line">+--------+------------+-------------+</div><div class="line">| son_id | son_name   | parent_name |</div><div class="line">+--------+------------+-------------+</div><div class="line">|      1 | 家用电器   | NULL        |</div><div class="line">|      2 | 电脑、办公 | NULL        |</div><div class="line">|      3 | 大家电     | 家用电器    |</div><div class="line">|      4 | 生活电器   | 家用电器    |</div><div class="line">|      5 | 平板电视   | 大家电      |</div><div class="line">|      6 | 空调       | 大家电      |</div><div class="line">|      7 | 电风扇     | 生活电器    |</div><div class="line">|      8 | 饮水机     | 生活电器    |</div><div class="line">|      9 | 电脑整机   | 电脑、办公  |</div><div class="line">|     10 | 电脑配件   | 电脑、办公  |</div><div class="line">|     11 | 笔记本     | 电脑整机    |</div><div class="line">|     12 | 超级本     | 电脑整机    |</div><div class="line">|     13 | 游戏本     | 电脑整机    |</div><div class="line">|     14 | CPU        | 电脑配件    |</div><div class="line">|     15 | 主机       | 电脑配件    |</div><div class="line">+--------+------------+-------------+</div></pre></td></tr></table></figure></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div></pre></td><td class="code"><pre><div class="line">使用左查询查询所有父类的子类</div><div class="line">mysql&gt; SELECT p.type_id parent_id, p.type_name parent_name, s.type_name son_name</div><div class="line">    -&gt; FROM tdb_goods_types AS p LEFT JOIN tdb_goods_types AS s</div><div class="line">    -&gt; ON p.type_id = s.parent_id</div><div class="line">    -&gt; ORDER BY parent_id;</div><div class="line">+-----------+-------------+----------+</div><div class="line">| parent_id | parent_name | son_name |</div><div class="line">+-----------+-------------+----------+</div><div class="line">|         1 | 家用电器    | 大家电   |</div><div class="line">|         1 | 家用电器    | 生活电器 |</div><div class="line">|         2 | 电脑、办公  | 电脑整机 |</div><div class="line">|         2 | 电脑、办公  | 电脑配件 |</div><div class="line">|         3 | 大家电      | 平板电视 |</div><div class="line">|         3 | 大家电      | 空调     |</div><div class="line">|         4 | 生活电器    | 电风扇   |</div><div class="line">|         4 | 生活电器    | 饮水机   |</div><div class="line">|         5 | 平板电视    | NULL     |</div><div class="line">|         6 | 空调        | NULL     |</div><div class="line">|         7 | 电风扇      | NULL     |</div><div class="line">|         8 | 饮水机      | NULL     |</div><div class="line">|         9 | 电脑整机    | 笔记本   |</div><div class="line">|         9 | 电脑整机    | 游戏本   |</div><div class="line">|         9 | 电脑整机    | 超级本   |</div><div class="line">|        10 | 电脑配件    | 主机     |</div><div class="line">|        10 | 电脑配件    | CPU      |</div><div class="line">|        11 | 笔记本      | NULL     |</div><div class="line">|        12 | 超级本      | NULL     |</div><div class="line">|        13 | 游戏本      | NULL     |</div><div class="line">|        14 | CPU         | NULL     |</div><div class="line">|        15 | 主机        | NULL     |</div><div class="line">+-----------+-------------+----------+</div><div class="line"></div><div class="line">// 查看父类的子类个数</div><div class="line">mysql&gt; SELECT p.type_id AS parent_id, p.type_name AS parent_name, count(p.parent_id) AS son_count</div><div class="line">    -&gt; FROM tdb_goods_types AS p LEFT JOIN tdb_goods_types AS s</div><div class="line">    -&gt; ON p.type_id = s.parent_id</div><div class="line">    -&gt; GROUP BY parent_name ORDER BY parent_id;</div><div class="line">+-----------+-------------+-----------+</div><div class="line">| parent_id | parent_name | son_count |</div><div class="line">+-----------+-------------+-----------+</div><div class="line">|         1 | 家用电器    |         2 |</div><div class="line">|         2 | 电脑、办公  |         2 |</div><div class="line">|         3 | 大家电      |         2 |</div><div class="line">|         4 | 生活电器    |         2 |</div><div class="line">|         5 | 平板电视    |         1 |</div><div class="line">|         6 | 空调        |         1 |</div><div class="line">|         7 | 电风扇      |         1 |</div><div class="line">|         8 | 饮水机      |         1 |</div><div class="line">|         9 | 电脑整机    |         3 |</div><div class="line">|        10 | 电脑配件    |         2 |</div><div class="line">|        11 | 笔记本      |         1 |</div><div class="line">|        12 | 超级本      |         1 |</div><div class="line">|        13 | 游戏本      |         1 |</div><div class="line">|        14 | CPU         |         1 |</div><div class="line">|        15 | 主机        |         1 |</div><div class="line">+-----------+-------------+-----------+</div></pre></td></tr></table></figure>
<h1 id="多表删除"><a href="#多表删除" class="headerlink" title="多表删除"></a>多表删除</h1><p><strong>DELETE tbl_name1,tbl_name2.. FROM table_references WHERE condidtions</strong></p>
<p>同时删除多个表的记录<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">DELETE t1,t2 FROM t1,t2 WHERE t1.name = t2.name;</div></pre></td></tr></table></figure></p>
<p>使用多表删除删除表中的重复数据<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div></pre></td><td class="code"><pre><div class="line">// 先用group by删选出名称相同的数量大于2的分组，筛选出的分组既是需要删除的记录</div><div class="line">SELECT goods_id,goods_name FROM tdb_goods GROUP BY goods_name HAVING count(goods_name) &gt;= 2</div><div class="line">+----------+-----------------------+</div><div class="line">| goods_id | goods_name            |</div><div class="line">+----------+-----------------------+</div><div class="line">|       18 |  HMZ-T3W 头戴显示设备 |</div><div class="line">|       19 | 商务双肩背包          |</div><div class="line">+----------+-----------------------+</div><div class="line"></div><div class="line">// 将上表与原表内连接，</div><div class="line">mysql&gt; SELECT * FROM tdb_goods AS t1</div><div class="line">    -&gt; INNER JOIN (SELECT goods_id,goods_name FROM tdb_goods GROUP BY goods_name HAVING count(goods_name) &gt;= 2) AS t2</div><div class="line">    -&gt; ON t1.goods_name = t2.goods_name ;</div><div class="line">+----------+-----------------------+---------------+----------+-------------+---------+------------+----------+-----------------------+</div><div class="line">| goods_id | goods_name            | goods_cate_id | brand_id | goods_price | is_show | is_saleoff | goods_id | goods_name            |</div><div class="line">+----------+-----------------------+---------------+----------+-------------+---------+------------+----------+-----------------------+</div><div class="line">|       18 |  HMZ-T3W 头戴显示设备  |            37 |        6 |    6999.000 |       1 |          0 |       18 |  HMZ-T3W 头戴显示设备 |</div><div class="line">|       19 | 商务双肩背包           |            37 |        6 |      99.000 |       1 |          0 |       19 | 商务双肩背包          |</div><div class="line">|       21 |  HMZ-T3W 头戴显示设备  |            37 |        6 |    6999.000 |       1 |          0 |       18 |  HMZ-T3W 头戴显示设备 |</div><div class="line">|       22 | 商务双肩背包           |            37 |        6 |      99.000 |       1 |          0 |       19 | 商务双肩背包          |</div><div class="line">+----------+-----------------------+---------------+----------+-------------+---------+------------+----------+-----------------------+</div><div class="line"></div><div class="line">// 最后删除重复的记录</div><div class="line">DELETE t1 FROM tdb_goods AS t1 </div><div class="line">INNER JOIN (SELECT goods_id,goods_name FROM tdb_goods GROUP BY goods_name HAVING count(goods_name) &gt;= 2) AS t2 </div><div class="line">ON t1.goods_name = t2.goods_name </div><div class="line">WHERE t1.goods_id &gt; t2.goods_id;</div></pre></td></tr></table></figure></p>

    

    
</div>


                

                <!-- Post Comments -->
                
                    


    <!-- 使用 changyan -->
    <div id="changyan-comment">
        <!--PC和WAP自适应版-->
<div id="SOHUCS" sid="2017/07/08/MySQL-子查询、表的连接/"  ></div>
<script type="text/javascript">
(function(){
var appid = 'cysVH2p6S';
var conf = '7d191ef850d424bb873df33179309db5';
var width = window.innerWidth || document.documentElement.clientWidth;
if (width < 960) {
window.document.write('<script id="changyan_mobile_js" charset="utf-8" type="text/javascript" src="https://changyan.sohu.com/upload/mobile/wap-js/changyan_mobile.js?client_id=' + appid + '&conf=' + conf + '"><\/script>'); } else { var loadJs=function(d,a){var c=document.getElementsByTagName("head")[0]||document.head||document.documentElement;var b=document.createElement("script");b.setAttribute("type","text/javascript");b.setAttribute("charset","UTF-8");b.setAttribute("src",d);if(typeof a==="function"){if(window.attachEvent){b.onreadystatechange=function(){var e=b.readyState;if(e==="loaded"||e==="complete"){b.onreadystatechange=null;a()}}}else{b.onload=a}}c.appendChild(b)};loadJs("https://changyan.sohu.com/upload/changyan.js",function(){window.changyan.api.config({appid:appid,conf:conf})}); } })(); </script>

    </div>
    <style>
        #changyan-comment{
            background-color: #eee;
            padding: 2pc;
        }
    </style>






                
            </div>

            <!-- Post Prev & Next Nav -->
            <nav class="material-nav mdl-color-text--grey-50 mdl-cell mdl-cell--12-col">
    <!-- Prev Nav -->
    
        <a href="/2017/07/09/独白/" id="post_nav-newer" class="prev-content">
            <button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon mdl-color--white mdl-color-text--grey-900" role="presentation">
                <i class="material-icons">arrow_back</i>
            </button>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            新篇
        </a>
    

    <!-- Section Spacer -->
    <div class="section-spacer"></div>

    <!-- Next Nav -->
    
        <a href="/2017/07/04/MySQL-操作数据表基本操作（增删改查）/" id="post_nav-older" class="next-content">
            旧篇
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon mdl-color--white mdl-color-text--grey-900" role="presentation">
                <i class="material-icons">arrow_forward</i>
            </button>
        </a>
    
</nav>

        </div>
    </div>



                    
                        <!-- Overlay For Active Sidebar -->
<div class="sidebar-overlay"></div>

<!-- Material sidebar -->
<aside id="sidebar" class="sidebar sidebar-colored sidebar-fixed-left" role="navigation">
    <div id="sidebar-main">
        <!-- Sidebar Header -->
        <div class="sidebar-header header-cover" style="background-image: url(/img/sidebar_header.jpg);">
    <!-- Top bar -->
    <div class="top-bar"></div>

    <!-- Sidebar toggle button -->
    <button type="button" class="sidebar-toggle mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon" style="display: initial;" data-upgraded=",MaterialButton,MaterialRipple">
        <i class="material-icons">clear_all</i>
        <span class="mdl-button__ripple-container">
            <span class="mdl-ripple">
            </span>
        </span>
    </button>

    <!-- Sidebar Avatar -->
    <div class="sidebar-image">
        <img src="/img/avatar.png" alt="wangchao's avatar">
    </div>

    <!-- Sidebar Email -->
    <a data-toggle="dropdown" class="sidebar-brand" href="#settings-dropdown">
        twilight0402@163.com
        <b class="caret"></b>
    </a>
</div>


        <!-- Sidebar Navigation  -->
        <ul class="nav sidebar-nav">
    <!-- User dropdown  -->
    <li class="dropdown">
        <ul id="settings-dropdown" class="dropdown-menu">
            
                <li>
                    <a href="http://mail.163.com" target="_blank" title="Email Me">
                        
                            <i class="material-icons sidebar-material-icons sidebar-indent-left1pc-element">email</i>
                        
                        Email Me
                    </a>
                </li>
            
        </ul>
    </li>

    <!-- Homepage -->
    
        <li id="sidebar-first-li">
            <a href="/" target="_self">
                
                    <i class="material-icons sidebar-material-icons">home</i>
                
                主页
            </a>
        </li>
        
    

    <!-- Archives  -->
    
        <li class="dropdown">
            <a href="#" class="ripple-effect dropdown-toggle" data-toggle="dropdown">
                
                    <i class="material-icons sidebar-material-icons">inbox</i>
                
                    归档
                <b class="caret"></b>
            </a>
            <ul class="dropdown-menu">
            <li>
                <a class="sidebar_archives-link" href="/archives/2017/08/">八月 2017<span class="sidebar_archives-count">5</span></a></li><li><a class="sidebar_archives-link" href="/archives/2017/07/">七月 2017<span class="sidebar_archives-count">23</span></a></li><li><a class="sidebar_archives-link" href="/archives/2017/06/">六月 2017<span class="sidebar_archives-count">13</span></a></li><li><a class="sidebar_archives-link" href="/archives/2017/04/">四月 2017<span class="sidebar_archives-count">7</span></a></li><li><a class="sidebar_archives-link" href="/archives/2017/03/">三月 2017<span class="sidebar_archives-count">3</span></a></li><li><a class="sidebar_archives-link" href="/archives/2017/02/">二月 2017<span class="sidebar_archives-count">2</span></a></li><li><a class="sidebar_archives-link" href="/archives/2017/01/">一月 2017<span class="sidebar_archives-count">8</span></a></li><li><a class="sidebar_archives-link" href="/archives/2016/12/">十二月 2016<span class="sidebar_archives-count">4</span></a></li><li><a class="sidebar_archives-link" href="/archives/2016/11/">十一月 2016<span class="sidebar_archives-count">3</span></a></li><li><a class="sidebar_archives-link" href="/archives/2016/09/">九月 2016<span class="sidebar_archives-count">3</span></a>
            </ul>
        </li>
        
    

    <!-- Categories  -->
    
        <li class="dropdown">
            <a href="#" class="ripple-effect dropdown-toggle" data-toggle="dropdown">
                
                    <i class="material-icons sidebar-material-icons">chrome_reader_mode</i>
                
                分类
                <b class="caret"></b>
            </a>
            <ul class="dropdown-menu">
                <li>
                <a class="sidebar_archives-link" href="/categories/CSS/">CSS<span class="sidebar_archives-count">9</span></a></li><li><a class="sidebar_archives-link" href="/categories/HTML/">HTML<span class="sidebar_archives-count">3</span></a></li><li><a class="sidebar_archives-link" href="/categories/JSP/">JSP<span class="sidebar_archives-count">6</span></a></li><li><a class="sidebar_archives-link" href="/categories/Java/">Java<span class="sidebar_archives-count">8</span></a></li><li><a class="sidebar_archives-link" href="/categories/JavaScript/">JavaScript<span class="sidebar_archives-count">2</span></a></li><li><a class="sidebar_archives-link" href="/categories/Linux/">Linux<span class="sidebar_archives-count">13</span></a></li><li><a class="sidebar_archives-link" href="/categories/MySQL/">MySQL<span class="sidebar_archives-count">7</span></a></li><li><a class="sidebar_archives-link" href="/categories/Servlet/">Servlet<span class="sidebar_archives-count">9</span></a></li><li><a class="sidebar_archives-link" href="/categories/jQuery/">jQuery<span class="sidebar_archives-count">7</span></a></li><li><a class="sidebar_archives-link" href="/categories/技术/">技术<span class="sidebar_archives-count">2</span></a></li><li><a class="sidebar_archives-link" href="/categories/日常/">日常<span class="sidebar_archives-count">1</span></a></li><li><a class="sidebar_archives-link" href="/categories/随笔/">随笔<span class="sidebar_archives-count">3</span></a>
            </ul>
        </li>
        
    

    <!-- Pages  -->
    
        <li>
            <a href="/tags" title="标签云">
                
                    <i class="material-icons sidebar-material-icons">cloud</i>
                
                标签云
            </a>
        </li>
        
            <li class="divider"></li>
        
    
        <li>
            <a href="/about" title="About">
                
                    <i class="material-icons sidebar-material-icons">person</i>
                
                About
            </a>
        </li>
        
    
        <li>
            <a href="/links" title="Social">
                
                    <i class="material-icons sidebar-material-icons">equalizer</i>
                
                Social
            </a>
        </li>
        
    

    <!-- Article Number  -->
    
        <li>
            <a href="/archives">
                文章总数
                <span class="sidebar-badge">71</span>
            </a>
        </li>
        
    
</ul>


        <!-- Sidebar Footer -->
        <!--
I'm glad you use this theme, the development is no so easy, I hope you can keep the copyright, I will thank you so much.
If you still want to delete the copyrights, could you still retain the first one? Which namely "Theme Material"
It will not impact the appearance and can give developers a lot of support :)

很高兴您使用并喜欢该主题，开发不易 十分谢谢与希望您可以保留一下版权声明。
如果您仍然想删除的话 能否只保留第一项呢？即 "Theme Material"
它不会影响美观并可以给开发者很大的支持和动力。 :)
-->

<!-- Sidebar Divider -->

    <div class="sidebar-divider"></div>


<!-- Theme Material -->


<!-- Help & Support -->
<!--

-->

<!-- Feedback -->
<!--

    <a href="https://github.com/viosey/hexo-theme-material/issues" target="_blank" class="sidebar-footer-text-a">
        <div class="sidebar-text mdl-button mdl-js-button mdl-js-ripple-effect sidebar-footer-text-div" data-upgraded=",MaterialButton,MaterialRipple">
        sidebar.feedback
        <span class="mdl-button__ripple-container"><span class="mdl-ripple"></span></span></div>
    </a>

-->

<!-- About Theme -->
<!--

    <a href="https://blog.viosey.com/index.php/Material.html" target="_blank" class="sidebar-footer-text-a">
        <div class="sidebar-text mdl-button mdl-js-button mdl-js-ripple-effect sidebar-footer-text-div" data-upgraded=",MaterialButton,MaterialRipple">
             sidebar.about_theme
            <span class="mdl-button__ripple-container"><span class="mdl-ripple"></span></span></div>
    </a>

-->

    </div>

    <!-- Sidebar Image -->
    

</aside>

                    

                    
                        <!-- Footer Top Button -->
                        <div class="toTop-wrap">
    <a href="#top" class="toTop">
        <i class="material-icons footer_top-i">expand_less</i>
    </a>
</div>

                    

                    <!--Footer-->
<footer class="mdl-mini-footer" id="bottom">
    
        <!-- Paradox Footer Left Section -->
        <div class="mdl-mini-footer--left-section sns-list">
    <!-- Twitter -->
    
        <a href="https://twitter.com/twitter" target="_blank">
            <button class="mdl-mini-footer--social-btn social-btn" style="background-image: url(/img/footer/footer_ico-twitter.svg);">
                <span class="visuallyhidden">Twitter</span>
            </button><!--
     --></a>
    

    <!-- Facebook -->
    
        <a href="https://www.facebook.com/facebook" target="_blank">
            <button class="mdl-mini-footer--social-btn social-btn" style="background-image: url(/img/footer/footer_ico-facebook.svg);">
                <span class="visuallyhidden">Facebook</span>
            </button><!--
     --></a>
    

    <!-- Google + -->
    
        <a href="https://www.google.com/" target="_blank">
            <button class="mdl-mini-footer--social-btn social-btn" style="background-image: url(/img/footer/footer_ico-gplus.svg);">
                <span class="visuallyhidden">Google Plus</span>
            </button><!--
     --></a>
    

    <!-- Weibo -->
    

    <!-- Instagram -->
    

    <!-- Tumblr -->
    

    <!-- Github -->
    
        <a href="https://github.com/1601436878" target="_blank">
            <button class="mdl-mini-footer--social-btn social-btn" style="background-image: url(/img/footer/footer_ico-github.svg);">
                <span class="visuallyhidden">Github</span>
            </button><!--
     --></a>
    

    <!-- LinkedIn -->
    

    <!-- Zhihu -->
    
        <a href="https://www.zhihu.com/people/wang-chao-50-78/activities" target="_blank">
            <button class="mdl-mini-footer--social-btn social-btn" style="background-image: url(/img/footer/footer_ico-zhihu.svg);">
                <span class="visuallyhidden">Zhihu</span>
            </button><!--
     --></a>
    

    <!-- Bilibili -->
    

    <!-- Telegram -->
    
</div>


        <!--Copyright-->
        <div id="copyright">
            Copyright&nbsp;©&nbsp;
            <script type="text/javascript">
                var fd = new Date();
                document.write(fd.getFullYear());
            </script>
            &nbsp;Twilight's Blog
        </div>

        <!-- Paradox Footer Right Section -->

        <!--
        I am glad you use this theme, the development is no so easy, I hope you can keep the copyright.
        It will not impact the appearance and can give developers a lot of support :)

        很高兴您使用该主题，开发不易，希望您可以保留一下版权声明。
        它不会影响美观并可以给开发者很大的支持。 :)
        -->

        <div class="mdl-mini-footer--right-section">
            <div>
                <div class="footer-develop-div">Powered by <a href="https://hexo.io" target="_blank" class="footer-develop-a">Hexo</a></div>
                <div class="footer-develop-div">Theme - <a href="https://github.com/viosey/hexo-theme-material" target="_blank" class="footer-develop-a">Material</a></div>
            </div>
        </div>
    
</footer>


                    <!-- Import File -->

    <script src="/js/lazyload.min.js"></script>
    <script src="/js/js.min.js"></script>



    <script src="/js/nprogress.js"></script>


<script type="text/javascript">
    NProgress.configure({
        showSpinner: true
    });
    NProgress.start();
    $('#nprogress .bar').css({
        'background': '#29d'
    });
    $('#nprogress .peg').css({
        'box-shadow': '0 0 10px #29d, 0 0 15px #29d'
    });
    $('#nprogress .spinner-icon').css({
        'border-top-color': '#29d',
        'border-left-color': '#29d'
    });
    setTimeout(function() {
        NProgress.done();
        $('.fade').removeClass('out');
    }, 800);
</script>





    <!-- Leancloud -->
    <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
    <script>
        AV.initialize('WJXlEXdVypRaytiRUYDL9Q4w-gzGzoHsz', 'qNN24AGgbaMqnDE7lqK8pwCD');
    </script>
    <script>
    function showTime(Counter) {
        var query = new AV.Query(Counter);
        $('.leancloud-views_num').each(function() {
            var url = $(this).attr('id').trim();
            query.equalTo('url', url);
            query.find({
                success: function(results) {
                    if (results.length === 0) {
                        var content = '0 ' + $(document.getElementById(url)).text();
                        $(document.getElementById(url)).text(content);
                        return;
                    }
                    for (var i = 0; i < results.length; i++) {
                        var object = results[i];
                        var content = object.get('time') + ' ' + $(document.getElementById(url)).text();
                        $(document.getElementById(url)).text(content);
                    }
                },
                error: function(object, error) {
                    console.log('Error: ' + error.code + ' ' + error.message);
                }
            });
        });
    }

    function addCount(Counter) {
      var Counter = AV.Object.extend('Counter');
      url = $('.leancloud-views_num').attr('id').trim();
      title = $('.leancloud-views_num').attr('data-flag-title').trim();
      var query = new AV.Query(Counter);
      query.equalTo('url', url);
      query.find({
          success: function(results) {
            if (results.length > 0) {
                var counter = results[0];
                counter.fetchWhenSave(true);
                counter.increment('time');
                counter.save(null, {
                    success: function(counter) {
                        var content =  counter.get('time') + ' ' + $(document.getElementById(url)).text();
                        $(document.getElementById(url)).text(content);
                    },
                    error: function(counter, error) {
                        console.log('Failed to save Visitor num, with error message: ' + error.message);
                    }
                });
            } else {
              var newcounter = new Counter();
              newcounter.set('title', title);
              newcounter.set('url', url);
              newcounter.set('time', 1);
              newcounter.save(null, {
                  success: function(newcounter) {
                      console.log('newcounter.get(\'time\')='+newcounter.get('time'));
                      var content = newcounter.get('time') + ' ' + $(document.getElementById(url)).text();
                      $(document.getElementById(url)).text(content);
                  },
                  error: function(newcounter, error) {
                      console.log('Failed to create');
                  }
              });
            }
        },
        error: function(error) {
            console.log('Error:' + error.code + ' ' + error.message);
        }
      });
    }
    $(function() {
        var Counter = AV.Object.extend('Counter');
        if ($('.leancloud-views_num').length === 1) {
            addCount(Counter);
        } else if ($('.post-title-link').length > 1) {
            showTime(Counter);
        }
    });
</script>







    <!-- 畅言公共 js 代码 start -->
		<script id="cy_cmt_num" src="https://changyan.sohu.com/upload/plugins/plugins.list.count.js?clientId=cysVH2p6S">
</script>
    <!-- 畅言公共 js 代码 end -->







<!-- Window Load-->
<script>
    $(window).load(function() {
        // Post_Toc parent position fixed
        $('.post-toc-wrap').parent('.mdl-menu__container').css('position', 'fixed');
    });
</script>

<!-- MathJax Load-->

<script>
    <!-- Offer LazyLoad -->
    queue.offer(function(){
        $('.lazy').lazyload({
            effect : 'show'
        });
    });

    <!-- Start Queue -->
    $(document).ready(function(){
        setInterval(function(){
            queue.execNext();
        },200);
    });
</script>

                </main>
            </div>
			<!--  -->
				<!--<script type="text/javascript" count="200" color="0,0,255" src="//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js"></script>-->
			<!--  -->
        </body>
    
</html>
